package com.spzx.product.api;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.*;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(contextId = "remoteProductService",
        value = ServiceNameConstants.PRODUCT_SERVICE,
        fallbackFactory = RemoteProductFallbackFactory.class)
public interface RemoteProductService {

    @GetMapping("/product/getTopSale")
    public R<List<ProductSku>> getTopSale(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/product/skuList/{pageNum}/{pageSize}")
    public R<TableDataInfo> skuList(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize, @SpringQueryMap SkuQuery skuQuery, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    @Operation(summary = "内部调用接口：查询sku详情")
    @GetMapping("/product/getSkuBySkuId/{skuId}")
    public R<ProductSku> getSkuBySkuId(@PathVariable("skuId")Long skuId);

    @Operation(summary = "内部调用接口：查询id查询spu详情")
    @GetMapping("/product/getSpu/{spuId}")
    public R<Product> getSpu(@PathVariable("spuId")Long spuId);
    @Operation(summary = "内部调用接口：查询spuid查询spu下所有的sku列表")
    @GetMapping("/product/getSkus/{spuId}")
    public R<List<ProductSku>> getSkus(@PathVariable("spuId")Long spuId);
    /*
        远程调用的本质 仍然是Http协议的网络请求
        - value = ServiceNameConstants.PRODUCT_SERVICE 可以获取到目标服务的ip+端口号
        - @GetMapping("/details/getDetails/{productId}") 可以获取到要访问的资源路径

        上面两个拼接才是目标资源的完整访问路径
     */
    @Operation(summary = "内部调用接口：根据productId查询详情图列表")
    @GetMapping("/details/getDetails/{productId}")
    public R<ProductDetails> getDetails(@PathVariable("productId")Long productId);
}
